/*
 * @Author: error: git config user.name && git config user.email & please set dead value or install git
 * @Date: 2022-06-15 15:37:21
 * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
 * @LastEditTime: 2022-06-15 15:54:45
 * @FilePath: \tdyp614\src\views\blackoutControl\overviewStudy\util\request.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { getUUID } from "./httpService";
import { GIS_MAP_SECRET_KEY } from "../constant/index";
class Request {
  constructor(url, data) {
    this.url = url;
    this.data = data;
  }
  post() {
    let uid = getUUID();
    let timestamp = new Date().getTime();
    let securityKey = GIS_MAP_SECRET_KEY; // 此变量为微服务申请sn
    let xml = new XMLHttpRequest();
    let signInfo =
      "timestamp=" + timestamp + "&random=" + uid + "&secretkey=" + securityKey;

    xml.open("POST", this.url, true);
    xml.setRequestHeader("random");
    xml.setRequestHeader("timestamp", timestamp);
    xml.setRequestHeader("sign", sm3(signInfo).toUpperCase());
    xml.send(JSON.stringify(this.data))
    xml.onreadystatechange = function(){
        if (xml.readState === 4 && xml.status === 200) {
            console.log('success',xml);
        }else{
            console.log('fail----',xml);
        }
    }
  }
}

export default Request
